<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Introduction - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.serializer.introduction.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.serializer.introduction.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.serializer.html">Zend_Serializer</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.serializer.html">Zend_Serializer</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.serializer.adapter.html">Zend_Serializer_Adapter</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.serializer.introduction" class="section"><div class="info"><h1 class="title">Introduction</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Serializer</span> provides an adapter based interface to simply
        generate storable representation of <acronym class="acronym">PHP</acronym> types by different facilities,
        and recover.
    </p>

    <div class="example" id="zend.serializer.introduction.example.dynamic"><div class="info"><p><b>Example #1 Using Zend_Serializer dynamic interface</b></p></div>
        

        <div class="example-contents"><p>
            To instantiate a serializer you should use the factory method with the name of the
            adapter:
        </p></div>

        <pre class="programlisting brush: php">
$serializer = Zend_Serializer::factory(&#039;PhpSerialize&#039;);
// Now $serializer is an instance of Zend_Serializer_Adapter_AdapterInterface,
// specifically Zend_Serializer_Adapter_PhpSerialize

try {
    $serialized = $serializer-&gt;serialize($data);
    // now $serialized is a string

    $unserialized = $serializer-&gt;unserialize($serialized);
    // now $data == $unserialized
} catch (Zend_Serializer_Exception $e) {
    echo $e;
}
</pre>

    </div>

    <p class="para">
        The method  <span class="methodname">serialize()</span> generates a storable string. To regenerate
        this serialized data you can simply call the method  <span class="methodname">unserialize()</span>.
    </p>

    <p class="para">
        Any time an error is encountered serializing or unserializing,
        <span class="classname">Zend_Serializer</span> will throw a
        <span class="classname">Zend_Serializer_Exception</span>.
    </p>

    <p class="para">
        To configure a given serializer adapter, you can optionally add an array or an instance of
        <span class="classname">Zend_Config</span> to the  <span class="methodname">factory()</span> or to the
         <span class="methodname">serialize()</span> and  <span class="methodname">unserialize()</span> methods:
    </p>

    <pre class="programlisting brush: php">
$serializer = Zend_Serializer::factory(&#039;Wddx&#039;, array(
    &#039;comment&#039; =&gt; &#039;serialized by Zend_Serializer&#039;,
));

try {
    $serialized = $serializer-&gt;serialize(
        $data,
        array(&#039;comment&#039; =&gt; &#039;change comment&#039;)
    );

    $unserialized = $serializer-&gt;unserialize(
        $serialized,
        array(/* options for unserialize */)
    );
} catch (Zend_Serializer_Exception $e) {
    echo $e;
}
</pre>


    <p class="para">
        Options passed to the  <span class="methodname">factory()</span> are valid for the instantiated
        object. You can change these options using the  <span class="methodname">setOption(s)</span> method.
        To change one or more options only for a single call, pass them as the second argument to
        either the  <span class="methodname">serialize()</span> or  <span class="methodname">unserialize()</span>
        method.
    </p>

    <div class="example" id="zend.serializer.introduction.example.static.php"><div class="info"><p><b>Example #2 Using the Zend_Serializer static interface</b></p></div>
        

        <div class="example-contents"><p>
            You can register a specific serializer adapter as a default serialization adapter for
            use with <span class="classname">Zend_Serializer</span>. By default, the
            <span class="classname">PhpSerialize</span> adapter will be registered, but you can change this
            option using the  <span class="methodname">setDefaultAdapter()</span> static method.
        </p></div>

        <pre class="programlisting brush: php">
Zend_Serializer::setDefaultAdapter(&#039;PhpSerialize&#039;, $options);
// or
$serializer = Zend_Serializer::factory(&#039;PhpSerialize&#039;, $options);
Zend_Serializer::setDefaultAdapter($serializer);

try {
    $serialized   = Zend_Serializer::serialize($data, $options);
    $unserialized = Zend_Serializer::unserialize($serialized, $options);
} catch (Zend_Serializer_Exception $e) {
    echo $e;
}
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.serializer.html">Zend_Serializer</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.serializer.html">Zend_Serializer</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.serializer.adapter.html">Zend_Serializer_Adapter</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.serializer.html">Zend_Serializer</a></li>
  <li class="active"><a href="zend.serializer.introduction.html">Introduction</a></li>
  <li><a href="zend.serializer.adapter.html">Zend_Serializer_Adapter</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>